package com.xx.springsecuritydemo.main.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloController {
    @RequestMapping("/hello")
    public void hello() {
        new Thread(() -> {
            Authentication auth = SecurityContextHolder.getContext().getAuthentication();
            User principal = (User) auth.getPrincipal();
            System.out.println("身份 :" + principal.getUsername());
            System.out.println("凭证 :" + auth.getCredentials());
            System.out.println("权限 :" + auth.getAuthorities());
        });
    }

    @RequestMapping("/hello-world")
    @ResponseBody
    public String helloWorld() {
        return "hello world";
    }
}
